#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SUM 10
#define MAX 100
typedef enum
{
    false,
    true
} bool;

float operate(float, float, char);

int main()
{
    printf("************运算器************\n");
    float value[SUM];
    char operators[SUM];
    char str[MAX];
    int valueLen, operatorsLen;
    valueLen = operatorsLen = 0;
    if (fgets(str, MAX, stdin) != NULL)
    {
        int length = strlen(str) - 1;
        if (str[length - 1] != '=')
        {
            printf("please input '=' at the end\n");
        }
        else
        {
            int start = 0;
            for (int i = 0; i < length; i++)
            {
                bool flag = false;
                switch (str[i])
                {
                case '+':
                    flag = true;
                    operators[operatorsLen++] = '+';
                    break;
                case '-':
                    flag = true;
                    operators[operatorsLen++] = '-';
                    break;
                case '*':
                    flag = true;
                    operators[operatorsLen++] = '*';
                    break;
                case '/':
                    flag = true;
                    operators[operatorsLen++] = '/';
                    break;
                case '=':
                    flag = true;
                    break;
                default:
                    break;
                }
                if (flag)
                {
                    char valueTmp[MAX];
                    for (int j = 0; j <= (i - start + 1); j++)
                    {
                        valueTmp[j] = str[start++];
                    }
                    value[valueLen++] = atof(valueTmp);
                    start = i + 1;
                }
                flag = false;
            }
        }
    }
    else
    {
        printf("please restart!\n");
    }

    float leftValue = value[0];
    int count = 0;
    while (count < operatorsLen)
    {
        leftValue = operate(leftValue, value[count + 1], operators[count]);
        count++;
    }
    printf("The result is: %2.2f\n", leftValue);

    return 0;
}
